package com.zbcz.erp.dialog

import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.widget.EditText
import android.widget.TextView
import com.zbcz.erp.R
import com.zbcz.erp.util.onSingleClick

class CancelDialog(context: Context) : Dialog(context, R.style.CommonDialog) {

    private lateinit var tvTitle: TextView
    private lateinit var tvConfirm: TextView
    private lateinit var tvCancel: TextView
    private lateinit var edContent: EditText

    var onConfirmListener: (() -> Unit)? = null

    init {
        // 设置布局 348dp 241dp
        setContentView(R.layout.item_cancel_dialog)
        // 设置对话框在屏幕中居中显示
        val windowAttributes = window?.attributes
        windowAttributes?.gravity = Gravity.CENTER
        window?.attributes = windowAttributes
        setCanceledOnTouchOutside(false)
        initViews()
        setCanceledOnTouchOutside(true)
    }

    private fun initViews() {
        tvTitle = findViewById(R.id.tv_title)
        tvConfirm = findViewById(R.id.tv_confirm)
        tvCancel = findViewById(R.id.tv_cancel)
        edContent = findViewById(R.id.ed_content)
        tvCancel.onSingleClick {
            dismiss()
        }
        tvConfirm.onSingleClick {
            onConfirmListener?.invoke()
            dismiss()
        }
    }
}